import { onMounted, onActivated, onUnmounted, ref, unref, nextTick } from "vue"
export function useScrollRecover(el) {
    const scrollTop = ref(0)
    const onScroll = (val) => {
        scrollTop.value = val.target.scrollTop
    }

    onMounted(() => {
        let scrollEl = el.value?.layout.table.refs.bodyWrapper
        scrollEl.addEventListener('scroll', onScroll, true)
    })
    onActivated(async () => {
        await nextTick()
        el.value?.setScrollTop(scrollTop.value)
    })

    // unmounted时记得取消监听
    onUnmounted(() => {
        let scrollEl = el.value?.layout.table.refs.bodyWrapper
        scrollEl?.removeEventListener('scroll', onScroll)
    })

}